<template>
  <div class="home" :style="{opacity:opacity}">
    <div class="bg000">
      <div class="container">
        <div class="top">
          <div class="ipt ">
            <input v-model="keyword" @keydown.enter="handleEnter" @blur="showTags" @click="handleTags" type="text">
            <i @click="handleFdj" class="iconfont fdj icon-search"></i>
            <div class="tags" :style="{display:tags_display}">
              <span @click="goMore('switchs')">Switchs</span>
              <span @click="goMore('box')">Box</span>
              <span @click="goMore('gmk')">GMK</span>
            </div>
          </div>
        </div>
        <div class="main">
          <div class="banner">
            <Banner/>
          </div>
          <div class="group">
            <Group/>
          </div>
        </div>
      </div>
    </div>
    <div class="bg111">
      <div class="container">
        <Discount/>
      </div>
    </div>
    <div class="container">
      <Lists/>
    </div>
    <Options>
      <div @click="handleFdj" v-show="isSearch" class="btn">
        <i class="iconfont icon-search"></i>
      </div>
    </Options>
  </div>
</template>

<script>
import Banner from './components/Banner.vue'
import Group from './components/Group.vue'
import Discount from './components/Discount.vue'
import Lists from './components/Lists.vue'
import Options from '../../components/Options'

export default {
  components:{
    Banner,
    Group,
    Discount,
    Lists,
    Options
  },
  data() {
    return {
      isSearch:false,
      isCart:false,
      keyword:'',
      opacity:0,
      tags_display:'block',
    }
  },
  mounted(){
    this.$bus.$emit('add')
    window.addEventListener('scroll' ,this.handleScroll)
    window.addEventListener('scroll' ,this.scrollWindow)
  },
  methods:{
    handleScroll(){
      var scrollTop = window.scrollY
      this.opacity = scrollTop/700
      if(this.opacity >= 1){
        this.opacity = 1
      }
    },
    handleTags(){
      this.tags_display = 'none'
      window.scrollTo({top:700,behavior:"smooth"})
    },
    
    handleFdj(){
      window.scrollTo({top:700,behavior:"smooth"})
    },
    showTags(){
      this.tags_display = 'block'
      this.keyword=""
    },
    scrollWindow(){
      var scrollY = window.scrollY
      if(scrollY >= 800){
        this.isSearch = true
      }else{
        this.isSearch = false
      }
    },
    handleEnter(){
      this.$router.push(`/search?keyword=${this.keyword}`)
    }
  },
  beforeDestroy(){
    window.removeEventListener('scroll' ,this.handleScroll)
    window.removeEventListener('scroll' ,this.scrollWindow)
  }
}
</script>

<style scoped>
  .home{
    background: #fff;
    margin-top:743px;
    color:  #fff;
  }
  .top{
    padding-top: 40px;
    overflow: hidden;
  }
  .ipt{
    margin: 10px;
    float: right;
    width: 600px;
    outline: none;
    border: 2px solid #777;
    position: relative;
  }
  .ipt>input{
    width: 80%;
    font-size: 18px;
    background-color: transparent;
    color: #fff;
    border: none;
    outline: none;
    padding: 14px;
  }
  .fdj{
    cursor: pointer;
    font-size: 30px;
    color: #777;
    padding: 10px;
    border-left: 2px solid #777;
    float: right;
  }
  .tags{
    position: absolute;
    top: 3px;
  }
  .tags>span{
    padding: 5px 13px ;
    display: inline-block;
    background-color: #232323;
    color: #606060;
    font-size: 13px;
    line-height: 18px;
    margin: 10px;
    cursor: pointer;
    user-select: none;
    transition: background-color .2s,color .2s;
  }
  .tags>span:hover{
    background-color: hsla(0,0%,100%,.31);
    color: #fff;
  }
  .main{
    display: flex;
    justify-content: space-around;
    padding: 50px 0;
  }
  .banner{
    width: 600px;
  }
  .group{
    height: 412px;
    width: 360px;
    /* border: 1px solid #fff; */
  }
  .bg000{
    background-color: #000;
  }
  .bg111{
    background-color: #151618;
  }
  .options{
    position: fixed;
    bottom:80px;
    right: 80px;
  }
  .btn{
    width: 52px;
    height: 52px;
    background: rgb(243, 254, 252);
    border: 1px solid rgb(255, 255, 255);
    box-shadow: rgb(129 234 215) 0px 8px 20px -8px;
    color: rgb(27, 229, 192);
    margin-top: 14px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    cursor: pointer;
    border-radius: 50%;
    transition: .15s ease;
    z-index: 100;
    position: relative;
  }
  .num{
    position: absolute;
    top: 0;
    right: 4px;
    background: #1be5c0;
    font-size: 12px;
    color: #fff;
    height: 18px;
    line-height: 18px;
    border-radius: 9px;
    padding: 0 9px;
    font-weight: 700;
    transform: translateX(50%);
  }
  .btn:hover{
    transform: translateY(-3px);
    box-shadow: 0 8px 20px -8px #02dbb4;
  }
  .btn>i{
    font-size: 30px;
  }
  
</style>